import  React from 'react'


export  default  class LifeCom    extends  React.Component {

    constructor(props) {
        super(props)

        this.state={
            val:'hello react 生命周期 我来了',
            count:0
        }
    }


    componentWillMount() {

        console.log('componentWillMount')

    }


    componentDidMount() {

        console.log('接受父组件传递过来的值',this.props)

        //发送请求的

        console.log('componentDidMount')


      this.timeId= setTimeout(()=>{
            this.setState({
                val:'我被改变了'
            })
        },2000)

    }

    shouldComponentUpdate(preProps,nextProps) {

        // console.log(this.state.val)
        console.log('preProps',preProps)

        console.log('nextProps',nextProps)
        console.log('shouldComponentUpdate')
        return  true
    }

    componentWillUpdate() {
        console.log('componentWillUpdate')
    }


    componentDidUpdate() {
        console.log('componentDidUpdate')
    }


    componentWillReceiveProps() {
        console.log('componentWillReceiveProps')
    }


    add=()=>{
    setInterval(() => {
        this.setState({
            count:++this.state.count
        })
    }, 2000);
    }


    render() {
          let {val}=this.state
          let {data}=this.props
        return(
            <div>
                <h2> {val} </h2>


                <div>  显示父组件的值:   {data}</div>

                <button onClick={this.add}>点击++</button>

                
            </div>
        )
    }
}